package com.chen.manager.controller;

import com.chen.manager.service.CategoryBrandService;
import com.chen.model.dto.product.CategoryBrandDto;
import com.chen.model.entity.product.Category;
import com.chen.model.entity.product.CategoryBrand;
import com.chen.model.vo.common.Result;
import com.chen.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author cgj
 * @date 3/8/25 9:20 AM
 */
@RestController
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {
    @Autowired
    private CategoryBrandService categoryBrandService;

    @DeleteMapping("/{id}")
    public Result delCategoryBrand(@PathVariable Long id){
        categoryBrandService.delCategoryBrand(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改
     * @param categoryBrandDto
     * @return
     */
    @PutMapping("/edit")
    public Result editCategoryBrand(@RequestBody CategoryBrandDto categoryBrandDto){
        categoryBrandService.editCategoryBrand(categoryBrandDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 新增 品牌分类
     * @param categoryBrandDto
     * @return
     */
    @PostMapping("/sava")
    public Result sava(@RequestBody CategoryBrandDto categoryBrandDto){
        categoryBrandService.sava(categoryBrandDto);
        return  Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 分页查询 条件 分类id和品牌id
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("{pageNum}/{pageSize}")
    public Result<PageInfo<CategoryBrand>> showByPageAndCidPid(@PathVariable Integer pageSize,
                                                               @PathVariable Integer pageNum,
                                                               CategoryBrandDto categoryBrandDto
                                                            ){
        PageInfo<CategoryBrand> pageInfo=categoryBrandService.showByPageAndCidPid(pageNum,pageSize,categoryBrandDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
}
